﻿/// 基于.net6 和 CancellationTokenSource 、 CancellationToken 以及 信号量： ManualResetEvent 实现的 长期任务的开始、暂停、停止。
// See https://aka.ms/new-console-template for more information
using ConsoleTest;
var cts = new CancellationTokenSource();
LongTaskService instance = new LongTaskService(cts.Token);
Console.WriteLine("please key 'start' doing task and key 'pause' pause task! And you input 'stop' stop task!");
while (true)
{
    Console.WriteLine("please input your command...");
    Console.ForegroundColor = ConsoleColor.Green;
    var input = Console.ReadLine();
    if(input?.ToLower() == "start")
    {
        instance.StartTask();
    }
    else if(input?.ToLower() =="pause")
    {
        instance.PauseTask();
    }
    else if (input?.ToLower() == "stop")
    {
        //一秒之后取消任务
        cts.CancelAfter(TimeSpan.FromSeconds(1));
    }
    else
    {
        Console.ForegroundColor = ConsoleColor.Red;
        Console.WriteLine("please input right command!!");
        continue;
    }
}